package cn.kgc.crowdfundingadmin.service;


import cn.kgc.crowdfundingadmin.mapper.dvertisementMapper;
import cn.kgc.crowdfundingadmin.pojo.dvertisement;
import cn.kgc.crowdfundingadmin.pojo.dvertisementExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service("advertisementService")
public class AdvertisementServiceImpl implements AdvertisementService {

    @Resource
    dvertisementMapper advertisementMapper;

    @Override
    public PageInfo<dvertisement> getAllAdvertisement(Integer pageNum, Integer pageSize, String keyWord) {
        PageHelper.startPage(pageNum,pageSize);
        dvertisementExample example=new dvertisementExample();
        dvertisementExample.Criteria criteria = example.createCriteria();
        criteria.andNameLike("%"+keyWord+"%");
        List<dvertisement> advertisements = advertisementMapper.selectByExample(example);
        PageInfo<dvertisement> pageInfo=new PageInfo<>(advertisements);
        return  pageInfo;
    }

    @Override
    public List<dvertisement> getAll(List<Integer> advertisementIdList) {
        dvertisementExample example=new dvertisementExample();
        dvertisementExample.Criteria criteria = example.createCriteria();
        criteria.andIdIn(advertisementIdList);
        List<dvertisement> advertisements = advertisementMapper.selectByExample(example);
        return advertisements;
    }

    @Override
    public void batchRemove(List<Integer> advertisementIdList) {
        dvertisementExample example=new dvertisementExample();
        dvertisementExample.Criteria criteria = example.createCriteria();
        criteria.andIdIn(advertisementIdList);
        advertisementMapper.deleteByExample(example);
    }

    @Override
    public void saveAdvertisement(String name, String iconpath, Integer status, String url, Integer userid) {
        advertisementMapper.insert(new dvertisement(status, null, name, null, null, null));
    }

    @Override
    public void updateCert(dvertisement advertisement) {
        advertisementMapper.updateByPrimaryKeySelective(advertisement);
    }






}
